package simulationEnviroment;

import simulationEngine.SimulationEngine;
import datatypes.ScenarioDescription;

public class SimulationEnviroment {
	// Variables
	private SimulationEngine engine = null;
	
	private Clock clock = null;
	private Processor processor = null;
	private ScenarioDescription scenDesc = null;
	private Queue traLayPara = null;
	
	// Methods
	public SimulationEnviroment(SimulationEngine engine) {
		this.engine = engine;
		this.scenDesc = engine.getScenarioParameter();
		//initialize Elements in SimulationEnviroment
		this.getClock();
		this.getProcessor();
		this.getQueue();
	}


	
	public Clock getClock() {
		if (clock == null) {
			clock = new Clock(engine);
		}
		return clock;
	}

	public Processor getProcessor() {
		if (processor == null) {
			processor = new Processor(engine);
		}
		return processor;
	}

	public Queue getQueue() {
		if (traLayPara == null) {
			traLayPara = new Queue();
		}
		return traLayPara;
	}

	
	public ScenarioDescription getScenarioDescription(){
		return scenDesc;
	}
	
	public void startSimulation(){
		this.getProcessor().prepareEnviromentForNextStep();
		this.getClock().onProcessorReady();
	}
	
	public void onStepComplete(int StepID){
		engine.countStepIsDone();
		if (engine.isSequenceComplete()){
			//do nothing until user decided it
		} else {
			this.getProcessor().prepareEnviromentForNextStep();
			this.getClock().onProcessorReady();							
		}
	}
}
